package com.ac.interceptor;
import com.ac.utils.JWTUtil;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import java.util.Map;
@Component
public class LoginInterceptor implements HandlerInterceptor {
    public static final  String                   SWAGGER_TOKEN = "fbc545a91cc94fe89296828a25a7e08e" +
            "@9085553879028596738";
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)throws Exception{
//验证令牌
        String token=request.getHeader("Authorization");
        //验证token
        try {
            Map<String, Object> c= JWTUtil.parseToken(token);
            return true;
        }
        catch (Exception e){
            response.setStatus(401);
            return false;
        }
    }
}
